{*******************************************************************************
* The contents of this file are used with permission, subject to the Mozilla   *
* Public License Version 1.1 (the "License"); you may not use this file except *
* in compliance with the License. You may obtain a copy of the License at      *
* http://www.mozilla.org/MPL/                                                  *
*                                                                              *
* Software distributed under the License is distributed on an "AS IS" basis,   *
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for *
* the specific language governing rights and limitations under the License.    *
*                                                                              *
* The Original Code is distributed as part of the "mediate" product and is     *
* Copyright (C) @home media limited. All Rights Reserved.                      *
*                                                                              *
* Email: support@athomemedia.co.uk                                             *
* Web:   http://www.athomemedia.co.uk                                          *
*******************************************************************************}

unit BaseMsgForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, pngimage;

const
  STANDARD_DESCRIPTION = 'Please visit our website at www.athomemedia.co.uk for ' +
                         'further information or assistance.';

type
  TfrmBaseMessage = class(TForm)
    Label2: TLabel;
    lbTitle: TLabel;
    lbVersion: TLabel;
    lbDesc: TLabel;
    btLeft: TButton;
    btCentre: TButton;
    pbFooter: TPaintBox;
    btRight: TButton;
    imgCompanyLogo: TImage;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure pbFooterPaint(Sender: TObject);
  private
    { Private declarations }
  protected
    { Protected declarations }
   procedure CreateParams(var Params: TCreateParams); override;
   procedure LoadImage;
  public
    { Public declarations }
  end;

var
  frmBaseMessage: TfrmBaseMessage;

implementation

{$R *.dfm}

procedure TfrmBaseMessage.CreateParams(var Params: TCreateParams);
begin
  inherited;

  // Set flag to display drop shadow effects with our form
  with Params.WindowClass do Style := Style or CS_DROPSHADOW;
end;

procedure TfrmBaseMessage.FormCreate(Sender: TObject);
begin
  // Load company logo image from common_images resource file
  LoadImage;

  // Populate standard boilerplate
  lbDesc.Caption := STANDARD_DESCRIPTION;

  // Enable drop shadow effect for all flagged windows
  SystemParametersInfo(SPI_SETDROPSHADOW, 0, Pointer(1), 0);
end;

procedure TfrmBaseMessage.FormDestroy(Sender: TObject);
begin
  // Disable drop shadow effect for all flagged windows
  SystemParametersInfo(SPI_SETDROPSHADOW, 0, Pointer(0), 0);
end;

procedure TfrmBaseMessage.pbFooterPaint(Sender: TObject);
var
  Rect: TRect;
begin
  with Sender as TPaintBox do
  begin
    Rect := GetClientRect;

    with Canvas do
    begin
      // Draw vertical separator
      Pen.Style := psSolid;
      Pen.Color := clBtnShadow;
      MoveTo(Rect.Left, Rect.Top);
      LineTo(Rect.Right, Rect.Top);
      Inc(Rect.Top);
      Pen.Color := clBtnHighlight;
      MoveTo(Rect.Left, Rect.Top);
      LineTo(Rect.Right, Rect.Top);
      Inc(Rect.Top);

      // Fill client area
      Brush.Color := clBtnFace;
      FillRect(Rect);
    end;
  end;
end;

procedure TfrmBaseMessage.LoadImage;
var
  TempImage: TPNGObject;
begin
  // Use temporary PNG image to load from resource
  TempImage := TPNGObject.Create;
  try
    TempImage.LoadFromResourceName(hInstance, 'SP_IMG_LOGO');
    imgCompanyLogo.Picture.Graphic := TempImage;
  finally
    TempImage.Free;
  end;
end;

end.
